package com.wang.springbootinit.controller.teacher;

import com.wang.springbootinit.common.BaseResponse;
import com.wang.springbootinit.common.ResultUtils;
import com.wang.springbootinit.model.dto.question.QuestionAddRequest;
import com.wang.springbootinit.model.dto.question.QuestionUpdateRequest;
import com.wang.springbootinit.model.entity.Question;
import com.wang.springbootinit.service.QuestionService;
import com.wang.springbootinit.service.ResearchChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 统考题目管理
 */
@RestController
@RequestMapping("/teacher/examination/question")
public class ExaminationQuestionController {

    @Autowired
    private QuestionService questionService;
    
    @Autowired
    private ResearchChapterService chapterService;

    /**
     * 根据章节ID查询题目列表
     * @param chapterId 章节ID
     * @param type 题目类型（选填）
     * @param category 题目分类（选填）
     */
    @GetMapping("/list")
    public BaseResponse<List<Question>> getQuestionList(
            @RequestParam Long chapterId,
            @RequestParam(required = false) Integer type,
            @RequestParam(required = false) Integer category) {
        return ResultUtils.success(questionService.getQuestionsByChapter(chapterId, type, category));
    }

    /**
     * 添加题目到指定章节
     */
    @PostMapping("/add")
    public BaseResponse<Boolean> addQuestion(@RequestBody QuestionAddRequest questionAddRequest) {
        return ResultUtils.success(questionService.addQuestion(questionAddRequest));
    }

    /**
     * 删除题目
     */
    @PostMapping("/delete/{id}")
    public BaseResponse<Boolean> deleteQuestion(@PathVariable Long id) {
        return ResultUtils.success(questionService.removeById(id));
    }

    /**
     * 编辑题目
     */
    @PostMapping("/update")
    public BaseResponse<Boolean> updateQuestion(@RequestBody QuestionUpdateRequest questionUpdateRequest) {
        return ResultUtils.success(questionService.updateQuestion(questionUpdateRequest));
    }
}
